<?php
// $Id$

/**
 * Controller_Admin_Card 控制器
 */
class Controller_Admin_Card extends Controller_Abstract
{
	function _format_appendSql()
	{
		if (isset($_SESSION['acct']))
		{
			if ($_SESSION['acct']['admin_id'] == -1 && $_SESSION['acct']['agent_id'] == -1)
			{
			//为管理
				//$append['']
				$append['admin_id'] = $_SESSION['acct']['id'];
				//$append['agent_id'] = -1;
				//$append= array();
			}else
			{
				$append['admin_id'] = $_SESSION['acct']['admin_id'];
				$append['agent_id'] = Acct::_get_have_acctid($_SESSION['acct']['id'], $_SESSION['acct']['admin_id']);
				$append['agent_id'][] = $_SESSION['acct']['id'];
			}
		}
		return $append;
	}
	
	function actiondel()
	{
		$this->union_table = Vouchercard::meta();
		$this->delete(array_merge(array('id'=>$this->_context->ids),$this->_format_appendSql()));
		Syslog::logs('删除普通卡ID:'.$this->_context->ids);
	}
	function actionagentdel()
	{
		$this->_checkAgentCardPower();
		if ($_SESSION['acct']['admin_id'] == -1 && $_SESSION['acct']['agent_id'] == -1){
		$this->union_table = Agentcard::meta();
		$this->delete(array('id'=>$this->_context->ids));
		Syslog::logs('删除代理卡ID:'.$this->_context->ids);
		}
		
	}
	function actionexp()
	{
	if ($_SESSION['acct']['newcard_level'] == 0)
		{
			exit('您没有权限生成卡密');
		}
		
		$query = $this->_format_appendSql();
		if ($this->_context->isGET())
		{
			$form = new Form_card_exp(url($this->_context->controller_name.'/'.$this->_context->action_name));
			
				
				//$form->element('rategroupid')->items =  Rategroup::_get_arrayinfo(array('agent_id'=>$_SESSION['acct']['id']));
		 		//$form->element('rategroupid_acall')->items = Rategroup::_get_arrayinfo(array('agent_id'=>$_SESSION['acct']['id']));
			$group = Rategroup::_get_agentRateinfo($_SESSION['acct']['id']);
			$group_a = Rategroup::_get_agentRateinfo($_SESSION['acct']['id']);
			$form->element('rategroupid')->items =  $group;
			$form->element('rategroupid_acall')->items = $group_a;
			if (!isset($query['agent_id']))
			{
				$items = Acct::_get_arrayinfo($query);
			}else
			{
				$items = array($_SESSION['acct']['id']=>$_SESSION['acct']['acctname']);
			}
			$form->element('agent_id')->items = $items;
			$this->_view['form'] = $form;
			$this->_viewname = '../card/cardexp';
		}else
		{
		//add users
			#检测充值ID
			if($this->_context->payid)
			{
				$payid = $this->_context->payid;
				$isOnly = Vouchercard::find('payid = ? and agent_id <> ?',$payid,intval($this->_context->agent_id))->getcount('id');
				if ($isOnly>0)
				{
					return $this->error('请更换充值ID');
				}
			}
			$userfile = isset($this->_context->cardfile)?trim($this->_context->cardfile):'';
			if (is_file($userfile))
			{
				//post
				$card = array(
				'agent_id'=>intval($this->_context->agent_id),
				'admin_id'=>Acct::cur_admin_id(),
				//'balance' =>$this->_context->balance,
				'limitbalance'=>$this->_context->limitbalance,
				//'expireddays'=>$this->_context->expireddays,
				'rategroupid'=>$this->_context->rategroupid,
				'rategroupid_acall'=>$this->_context->rategroupid_acall,
				'bindexten'=>'',
				'voucher_acctname'=>'',
				'payid'=>$this->_context->payid,
				'voucheredtype'=>intval($this->_context->voucheredtype)
				//'expireddate'=>date('Y-m-d',strtotime("+ {$this->_context->expireddays} day"))
				);
				
				$handle = fopen($userfile, 'r');
				if($handle)
				{
					$split_char = ',';
					$i = 0;
					$ok = 0;
					$no = 0;
					$line_num = 0;
					$err_line = '';
					while (!feof($handle))
					{
						$line_num +=1;
						$lineCard = fgets($handle,400);
						$Split_arr = explode($split_char, $lineCard);
						if(QValidator::validate_between(count($Split_arr), 4, 5))
						{
							if(strlen($Split_arr[0])>0 && strlen($Split_arr[1])>0 && strlen($Split_arr[2])>0 && strlen($Split_arr[3])>0 )
							{
								$card['cardname'] = $Split_arr[0];
								$card['password'] = $Split_arr[1];
								$card['balance'] = $Split_arr[2];
								$card['expireddays'] = $Split_arr[3];
								$card['expireddate'] = date('Y-m-d',time() + intval($Split_arr[3])*86400);
							if ($card['voucheredtype'] == 0)
							{
								//开户卡 置金额为0
								$card['balance'] = 0;
							}
								$vouch = Vouchercard::find('cardname = ?',$card['cardname'])->getOne();
								//$user = Acct::find('acctname = ?',$userArr['acctname'])->getOne();
								if($vouch->cardname)
								{
									$err_line .= ','.$line_num;
								}else
								{
									try {
										$vouch = new Vouchercard($card);
										$vouch->save(0,'create');
										$ok +=1;
									} catch (Exception $e) {
										$err_line .= ','.$line_num;
									}
								}
							}else
							{
								$no +=1;
								$err_line .= ','.$line_num;
								continue;
							}
						}else
						{
							$no +=1;
							$err_line .= ','.$line_num;
							continue;
						}
					}
					fclose($handle);
					//删除文件
					@unlink($cardfile);
					Syslog::logs('导入卡密:'.$ok.'条用户数据');
					return $this->success(sprintf('成功导入%d条记录，失败%d条，分别存在:%s',$ok,$no,$err_line));
				}else
				{
					return $this->error('文件打开失败');
				}
			}else
			{
				return $this->error('文件不存在,请重新上传');
			}
				
		}
	}
	
	function actionIndex()
	{
              $this->union_table = Vouchercard::meta();
              if(isset($_POST['vouchered']) && $_POST['vouchered'] == '')unset($_POST['vouchered']);
              $append = $this->_format_appendSql();
              $agent_id = intval($this->_context->agent_id);
              if (  $agent_id> 0 && $_SESSION['acct']['acclevel'] <> 0)
              {
              		if (isset($append['agent_id']) && in_array($agent_id, $append['agent_id']) )
              		{
              			
              			$append['agent_id'] = array($agent_id);
              		}
              }
              $this->_context->orderField = "id";
              $this->_context->orderDirection = "desc";
       $agent_list = Acct::_get_arrayinfo();
       $this->_view['agent_list'] = $agent_list;
       $this->lists($append);
	}
	function actionagentimport()
	{
		$this->_checkAgentCardPower();
	if (isset($_SESSION['acct']['is_one']) && $_SESSION['acct']['is_one'] == 1)
		{
			//$query = $this->_format_appendSql();
			if ($this->_context->isGET())
			{
				$form = new Form_card_agentimport(url($this->_context->controller_name.'/'.$this->_context->action_name));
				$form->element('card_prex')->value = date('Hi');	
				//$form->element('agent_id')->items = $items;
				$this->_view['form'] = $form;
				$this->_viewname = '../form/add';
			}else
			{
				//post
				$card = array(
						'balance' =>$this->_context->balance,
						'voucher_acctname'=>'',
						'vouchered_acctname'=>'',
						'vouchereddate'=>'0000-00-00',
						'agent_id'=>$_SESSION['acct']['acclevel'] == 0 ? -1 :$_SESSION['acct']['id'],
						'create_acctname'=>$_SESSION['acct']['acctname']
				);
					
				$card_num = intval($this->_context->card_number);
			
				$card_length = intval($this->_context->card_length);
				//代理设置的前最
			
				$preg_fix = intval($this->_context->card_prex);
			
			
				//$preg = intval($this->_context->preg_1);
				//$r_len = abs($card_length - strlen($preg_fix));
				$pwd_length = intval($this->_context->pwd_length);
				if ($pwd_length<=3)$pwd_length = 3;
				$improt_preg = intval($this->_context->improt_preg);
			
				for ($i = 1;$i<=$card_num;$i++)
				{
				$item = $preg_fix.(Helper_Common::get_rnd(0, $card_length-strlen($preg_fix)));
				$card['password'] = Helper_Common::get_rnd(0,$pwd_length);
				$card['cardname'] = $item;
				$status = Acct::make_agentcard( $card);
				}
				return $this->success('生成成功,请刷新后查看');
				Syslog::logs('生成代理充值卡:'.$card_num.'张');
			}
		}else
		{
			exit('只有运营以及1级代理才能管理');
		}
	}
	function actionagentindex()
	{
		$this->_checkAgentCardPower();
		if (isset($_SESSION['acct']['is_one']) && $_SESSION['acct']['is_one'] == 1)
		{
			if($_SESSION['acct']['admin_id'] == -1 && $_SESSION['acct']['agent_id'] == -1 )
			{
				$param = array(
							//'admin_id'=>$_SESSION['acct']['id']
						);
			}else
			{
				$param = array(
						'agent_id'=>$_SESSION['acct']['id']
				);
			}
			//$agent_list = Acct::_get_arrayinfo($param);
			//$this->_view['agent_list'] = $agent_list;
			$this->union_table = Agentcard::meta();
			$this->lists($param);
		}else
		{
			exit('只有运营以及1级代理才能管理');
		}
	}
	
	
	function actionimport()
	{
		
		
		if ($_SESSION['acct']['newcard_level'] == 0)
		{
			exit('您没有权限生成卡密');
		}
		
		$query = $this->_format_appendSql();
		if ($this->_context->isGET())
		{
			$form = new Form_card_import(url($this->_context->controller_name.'/'.$this->_context->action_name));
			
			//$form->element('preg_1')->value = time();
			$group = Rategroup::_get_agentRateinfo($_SESSION['acct']['id']);
			$group_a = Rategroup::_get_agentRateinfo($_SESSION['acct']['id']);
				$form->element('rategroupid')->items =  $group;
		 		$form->element('rategroupid_acall')->items = $group_a;
			if (!isset($query['agent_id']))
			{
				$items = Acct::_get_arrayinfo($query);
			}else
			{
				$items = array($_SESSION['acct']['id']=>$_SESSION['acct']['acctname']);
			}
			
			$package = Acctpackage::find('agent_id = ?',$_SESSION['acct']['id'])->setColumns('id,packagename')->getAll();
			if(count($package))
			{
				$package = Helper_Array::toHashmap($package, 'id','packagename');
				$packitem[0] = '不使用套餐';
				foreach ($package as $k=>$v)
				{
					$packitem[$k] = $v;
				}
				
			}else{
				$packitem = array(0=>'不使用套餐');
			}
			$form->element('packageid')->items = $packitem;
			$form->element('agent_id')->items = $items;
			$this->_view['form'] = $form;
			$this->_viewname = '../form/add';
		}else
		{
			#检测充值ID
			if($this->_context->payid)
			{
				$payid = $this->_context->payid;
				$isOnly = Vouchercard::find('payid = ? and agent_id <> ?',$payid,intval($this->_context->agent_id))->getcount('id');
				if ($isOnly>0)
				{
					return $this->error('请更换充值ID');
				}
			}
			if (!isset($this->_context->rategroupid) || !isset($this->_context->rategroupid_acall))
			{
				return $this->error('费率组必须选择');
			}
			$packid = intval($this->_context->packageid);
			if ($packid)
			{
				$packid_debit = Acctpackage::find('agent_id = ? and id = ?',intval($this->_context->agent_id),intval($this->_context->packageid))->getOne();
				if (!$packid_debit->id())
				{
					return $this->error('套餐不存在');
				}else if(floatval($packid_debit->debit) > floatval($this->_context->balance) ){
					return $this->error('启用套餐，必须设置卡余额大于套餐扣费金额');
				}
			}
			//post
			$card = array(
				'agent_id'=>intval($this->_context->agent_id),
				'admin_id'=>Acct::cur_admin_id(),
				'balance' =>$this->_context->balance,
				'limitbalance'=>$this->_context->limitbalance,
				'expireddays'=>$this->_context->expireddays,
				'rategroupid'=>$this->_context->rategroupid,
				'rategroupid_acall'=>$this->_context->rategroupid_acall,
				'bindexten'=>'',
				'voucher_acctname'=>'',
				'payid'=>$this->_context->payid,
				'expireddate'=>date('Y-m-d',strtotime("+ {$this->_context->expireddays} day")),
				'voucheredtype'=>intval($this->_context->voucheredtype),
				'cardtype'=>intval($this->_context->cardtype),
				'automoney'=>intval($this->_context->automoney),
				'packageid'=>intval($this->_context->packageid)
			);
			if ($card['voucheredtype'] == 0)
			{
				//开户卡
				$card['balance'] = 0;
			}
			
			if ($card['cardtype'] == 1 && ( intval($card['automoney']) > intval($card['balance']) ) )
			{
				return $this->error('对不起,月费必须小于开卡金额');die;
			}
			if($card['cardtype'] == 1 && intval($card['automoney']) <= 1)
			{
				return $this->error('对不起,月费必须大于0元');
			}
				$card_num = intval($this->_context->card_number);
				
				//$card_length = intval($this->_context->card_length);
				//代理设置的前最
// 				$tar_acct = Acct::find('id = ?',$card['agent_id'])->getOne();
// 				if(!$tar_acct->id()){
// 					return $this->error('不存在此代理');
// 				}else
// 				{
// 					$preg_fix = strlen($tar_acct->agent_prefix)>0?$tar_acct->agent_prefix:$tar_acct->id;	
// 				}
				
				
				//$preg = intval($this->_context->preg_1);
				//$r_len = abs($card_length - strlen($preg_fix));
				$pwd_length = intval($this->_context->pwd_length);
				if ($pwd_length<=3)$pwd_length = 3;
				//$improt_preg = intval($this->_context->improt_preg);
				
				for ($i = 1;$i<=$card_num;$i++)
				{
					$item = Helper_Common::get_rnd(0,8);
					$card['password'] = Helper_Common::get_rnd(0,$pwd_length);
					$card['cardname'] = $item;
					$status = Acct::make_card($_SESSION['acct']['id'], $card);
					if ($status == false)
					{
						$item = Helper_Common::get_rnd(0,8);
						$card['password'] = Helper_Common::get_rnd(0,$pwd_length);
						$card['cardname'] = $item;
						$status = Acct::make_card($_SESSION['acct']['id'], $card);
					}
				}
				Syslog::logs('生成用户充值卡:'.$card_num.'张');
				return $this->success('生成成功,请刷新后查看');
				
		}
	}
	function actiontimemoney()
	{
		if($this->_context->isGET())
		{
			$param = $this->_format_appendSql();
			if (isset($param['agent_id']))
			{
				$param['id'] = $param['agent_id'];
				unset($param['agent_id']);
			}
			if (isset($this->_context->id))
			{
				$param['id'] = intval($this->_context->id);
				$agent = Acct::find('id = ?',$param['id'])->setColumns('id,acctname')->asArray()->getAll(); //列出全部流量用户
					
				$agent = Helper_Array::toHashmap($agent, 'id','acctname');
		
				$this->_view['agent'] = ($agent);
			}else{
				$this->_view['agent'] = Acct::_get_arrayinfo($param); //列出全部流量用户
			}
				
				
			$param['discharge_level'] = 1;
				
		}else
		{
			$agent_id = intval($this->_context->agent_id);
			$money = $this->_context->money;
			$status = Acct::timemoney($agent_id, $money);
			if ($status === true)
			{
				$acct_name = Acct::getacctName($agent_id);
				Syslog::logs("为代理:{$acct_name}成功增加余额{$money}");
				return $this->success('充值成功');
			}else
			{
				return $this->error($status);
			}
		}
	}
	/**
	 * 1级使用
	 */
	function actiontimeagentpay()
	{
		if ($this->_context->isPOST())
		{
			$agent_id = trim($this->_context->agent_id);
			$agent = Acct::find('id = ? and agent_id = admin_id and agent_id <> -1',$agent_id)->getOne();
			
			if ($agent->id)
			{
				$agent_id = intval($agent->id);
				$cardname = $this->_context->cardname;
				$password = $this->_context->password;
				$status = Acct::use_agentcardOnCW($agent_id, $cardname, $password);
				
				if ($status === true)
				{
					$acct_name = Acct::getacctName($agent_id);
					Syslog::logs("使用代理充值卡{$cardname} 为 {$acct_name} 充值成功");
					return $this->success('充值成功,重新登录即可查看最新余额');
				}else
				{
					return $this->error('充值失败');
				}
			}else{
				return $this->error('代理不存在');
			}
			
		}else{
			$agent = Acct::find('agent_id = admin_id and agent_id <> -1')->setColumns('id,acctname')->asArray()->getAll(); //列出全部流量用户
			
			$agent = Helper_Array::toHashmap($agent, 'id','acctname');
				
			$this->_view['agent'] = ($agent);
			$cardname = trim($this->_context->cardname);
			$passwd = trim($this->_context->password);
			$this->_view['cardname'] = $cardname;
			$this->_view['password'] = $passwd;
				
		}
	}
	function actiontimepay()
	{
		if($this->_context->isGET())
		{
			$param = $this->_format_appendSql();
			if (isset($param['agent_id']))
			{
				$param['id'] = $param['agent_id'];
				unset($param['agent_id']);
			}
			if (isset($this->_context->id))
			{
				$param['id'] = intval($this->_context->id);
				$agent = Acct::find('id = ?',$param['id'])->setColumns('id,acctname')->asArray()->getAll(); //列出全部流量用户
			
				$agent = Helper_Array::toHashmap($agent, 'id','acctname');
				
				$this->_view['agent'] = ($agent);
			}else{
				$this->_view['agent'] = Acct::_get_arrayinfo($param); //列出全部流量用户
			}
			
			
			$param['discharge_level'] = 1;
			
		}else
		{
			$agent_id = intval($this->_context->agent_id);
			$cardname = $this->_context->cardname;
			$password = $this->_context->password;
			$status = Acct::use_agentcard($agent_id, $cardname, $password);
			if ($status === true)
			{
				$acct_name = Acct::getacctName($agent_id);
				Syslog::logs("使用代理充值卡{$cardname} 为 {$acct_name} 充值成功");
			return $this->success('充值成功,刷新页面即可查看最新余额');
			}else
			{
			return $this->error('充值失败');
			}
		}
	}
	function actionpay()
	{
		if ($this->_context->isGET())
		{
			$this->_view['cardname'] = $this->_context->cardname;
			$this->_view['password'] = $this->_context->password;
			
			
		}else
		{
			$acctname = $this->_context->acctname;
			$cardname = $this->_context->cardname;
			$password = $this->_context->password;
			if (!$acctname)
			{
				return $this->error('账号必须填写');
			}
			$status = Acctuser::use_card($acctname, $cardname, $password);
			if ($status === true)
			{
			
			Syslog::logs("使用用户充值卡{$cardname} 为 {$acctname} 充值成功");
			return $this->success('充值成功');
			}else
			{
			return $this->error($status);
			}
			
		}
	}
	function actionlog()
	{
		$this->union_table = Voucherlog::meta();
		if($_SESSION['acct']['acclevel'] == 3)
		{
		$this->lists(array('acctname'=>$_SESSION['acct']['acctname']));
		}else{
		$this->lists($this->_format_appendSql());
		}
		
	}
	function actiontransfer()
	{
		if ($this->_context->isGET())
		{
			
		}else
		{
			$tar_balance = $this->_context->tar_balance;
			$tar_acctname = $this->_context->tar_acctname;
			$acctname = $this->_context->acctname;
			$password = $this->_context->password;
			$status = Acctuser::transfer($acctname, $password, $tar_acctname, $tar_balance);
			if ($status === true)
			{
				Syslog::logs("{$acctname} 转账 {$tar_balance} 给 {$tar_acctname} ");
				return $this->success('转账成功');
			}else
			{
				return $this->error($status);
			}
		}
	}
	function actionoutput()
	{
		if($_SESSION['acct']['downloadcard_level'] ==0 && $_SESSION['acct']['acclevel'] != 0)
		{
			$output = new Helper_dboutput(array(array('您没有权限导出数据')));
			$output->output_txt();
			die;
		}
		$sql = ($_SESSION['lastsql']);
		$obj = call_user_func_array(array(Vouchercard::meta(),'find'), $sql);
		$outid = isset($this->_context->idflag) && $this->_context->idflag ? 'id,' : '';
		$data = $obj->setColumns($outid.'cardname, password, balance, expireddays')->asArray()->getAll();
		
		//$sql = "";
		//$param['id'] = $this->_context->ids;
		//$data = Vouchercard::find($cond)->setColumns('cardname, password, balance, expireddays, activedate, expireddate, voucher_acctname')->asArray()->getAll();
		$output = new Helper_dboutput($data);
		$output->output_txt();
	}
	function actionagentoutput()
	{
		$sql = ($_SESSION['lastsql']);
		$obj = call_user_func_array(array(Agentcard::meta(),'find'), $sql);
		$data = $obj->setColumns('cardname,password,balance,createtime,vouchered,voucher_acctname,vouchered_acctname')->asArray()->getAll();
		$output = new Helper_dboutput($data);
		$output->output_txt();
	}
	
	private function _checkAgentCardPower()
	{
		$set = Q::ini('appini/agentcard');
		#增加运营
		$acct = Acct::find('id = ?',$_SESSION['acct']['id'])->getOne();
		
		if (!array_key_exists($_SESSION['acct']['acctname'], $set) && $acct->is_Onelevel == false)
		{
			exit('须运营人员以及1级代理查看');
		}else{
			$_SESSION['acct']['is_one'] = true;
		}
	}
	
	function actionuserchange()
{
	if($_SESSION['acct']['update_level'] == 0 && $_SESSION['acct']['acclevel'] != 0)
	{
		return $this->error('对不起,您没有权限批量修改');
	}
		if ($this->_context->isGET())
		{
				$this->_view['rategroupid'] =  Rategroup::_get_arrayinfo(array('agent_id'=>$_SESSION['acct']['id']));
		 		$this->_view['rategroupid_acall']  = Rategroup::_get_arrayinfo(array('agent_id'=>$_SESSION['acct']['id']));
		}else {
			$param = $_SESSION['lastsql'];
			$obj = call_user_func_array(array(Vouchercard::meta(),'find'), $param);
			$acctUser = $obj->setColumns('id')->asArray()->getAll();
			//$sql = helper_disposeparam::parse($param);
			//$acct = Acctuser::find($param)->getAll();
			
			if (count($acctUser)>0)
			{
				$acctUser = Helper_Array::toHashmap($acctUser, 'id','id');
				$ids = Helper_Array::toHashmap($acctUser, 'id','id');
				$post = $_POST;
				$upsql = " UPDATE vouchercard set %s where id in (%s)";
				$setsql = array();
				if (($post['balance']))
				{
					$setsql[] = " balance =  ".intval($post['balance']);
				}
				if ($post['expireddays'])
				{
					$setsql[] = " expireddays = '{$post['expireddays']}'";
				}
				
				if (isset($post['enable']) && $post['enable'] != -1)
				{
					$setsql[] = " enable = ".intval($post['enable']);
				}
				if ($post['limitbalance'])
				{
					$setsql[] = " limitbalance = ".intval($post['limitbalance']);
				}
				
				if ($post['rategroupid'] && $post['rategroupid'] != -1)
				{
					$setsql[] = " rategroupid = ".intval($post['rategroupid']);
				}
				if ($post['rategroupid_acall'] && $post['rategroupid_acall'] != -1)
				{
					$setsql[] = " rategroupid_acall = ".intval($post['rategroupid_acall']);
				}
				if (count($setsql)>0)
				{
					$upsql = sprintf($upsql,implode(',',$setsql),implode(',',$acctUser));
					try {	
					QDB::getConn()->execute($upsql);
					return $this->success('修改成功');
					} catch (Exception $e) {
						return $this->error('修改失败');
					}
					
				}else{
					return $this->error('没有被修改的项目');
				}
				
			}else {
				return $this->error('没有匹配的数据');
			}
		}
	}
	/**
	 * 月卡扣费记录
	 */
	function actionmonthlog()
	{
		$this->union_table = Acctbgpaylog::meta();
		$class = isset($_REQUEST['class']) ? trim($_REQUEST['class']):'monthcard';
		if($_SESSION['acct']['acclevel'] == 3)
		{
			$this->lists(array('acctname'=>$_SESSION['acct']['acctname'],'class'=>$class));
		}else{
			$this->lists(array_merge($this->_format_appendSql(),array('class'=>$class)));
		}
	}
	function actionviplog()
	{
		$this->union_table = Acctbgpaylog::meta();
		$class = isset($_REQUEST['class']) ? trim($_REQUEST['class']):'vip';
		if($_SESSION['acct']['acclevel'] == 3)
		{
			$this->lists(array('acctname'=>$_SESSION['acct']['acctname'],'class'=>$class));
		}else{
			$this->lists(array_merge($this->_format_appendSql(),array('class'=>$class)));
		}
		$this->_viewname = 'monthlog';
	}
}


